package com.gd.iot.energy.controller.datamanage;

import com.gd.iot.energy.annotation.SystemLogRecordMonitor;
import com.gd.iot.energy.consts.SystemConsts;
import com.gd.iot.energy.entity.ResponseEntity;
import com.gd.iot.energy.pojo.common.vo.PageVO;
import com.gd.iot.energy.pojo.common.vo.ChartVO;
import com.gd.iot.energy.pojo.datamanage.vo.MeterFrozenPageVO;
import com.gd.iot.energy.pojo.datamanage.vo.MeterHistoryPageVO;
import com.gd.iot.energy.pojo.datamanage.vo.MeterRealtimePageVO;
import com.gd.iot.energy.pojo.datamanage.vo.MeterStatusPageVO;
import com.gd.iot.energy.service.datamanage.LogIotArchivesstateService;
import com.gd.iot.energy.service.datamanage.ReportNbWaterDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 数据管理-数据查询-NB表数据
 *
 * @author kris
 * @date Created at 2020/8/7 10:50
 */
@Api(value = "数据管理-数据查询-NB表数据",tags = "数据管理-数据查询-NB表数据")
@RestController
@RequestMapping("/admin/meterData")
public class MeterDataController {

    @Autowired
    private LogIotArchivesstateService logIotArchivesstateService;

    @Autowired
    private ReportNbWaterDataService reportNbWaterDataService;

    @ApiOperation("NB表状态数据分页列表")
    @SystemLogRecordMonitor("NB表状态数据分页列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "customerSerialnumber", value = "客户编号", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "customerName", value = "客户名称", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "archivesAddress", value = "表计地址", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "voltageStart", value = "电压大于等于", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "voltageEnd", value = "电压小于等于", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "beginDate", value = "开始时间", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "endDate", value = "结束时间", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "valve", value = "阀状态((关闭, 0)(开启, 1)UNKNOWN(未知, 2))", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "areaId", value = "区域id", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "pageNum", value = "页码", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "orderColumn", value = "排序字段", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "orderType", value = "排序类型(asc,desc)", dataType = "string", paramType = "query", example = "", required = false),
    })
    @PostMapping("/getNBMeterStatusPageVO")
    public ResponseEntity<PageVO<MeterStatusPageVO>> getNBMeterStatusPageVO(
            @RequestParam(value = "customerSerialnumber",required = false)String customerSerialnumber,
            @RequestParam(value = "customerName",required = false)String customerName,
            @RequestParam(value = "archivesAddress",required = false)String archivesAddress,
            @RequestParam(value = "voltageStart",required = false)String voltageStart,
            @RequestParam(value = "voltageEnd",required = false)String voltageEnd,
            @RequestParam(value = "beginDate",required = false)String beginDate,
            @RequestParam(value = "endDate",required = false)String endDate,
            @RequestParam(value = "valve",required = false)Integer valve,
            @RequestParam(value = "areaId",required = false)Integer areaId,
            @RequestParam(value = "pageSize",required = false,defaultValue = "10")Integer pageSize,
            @RequestParam(value = "pageNum",required = false,defaultValue = "1")Integer pageNum,
            @RequestParam(value = "orderColumn",required = false,defaultValue = "id") String orderColumn,
            @RequestParam(value = "orderType",required = false,defaultValue = "asc") String orderType
    ) {

        PageVO<MeterStatusPageVO> pageVO = logIotArchivesstateService.getNBMeterStatusPageVO(customerSerialnumber,customerName,
                archivesAddress,voltageStart,voltageEnd,beginDate,endDate,valve,areaId,pageSize,pageNum,orderColumn,orderType, SystemConsts.EquipType.NB);
        return new ResponseEntity<>(pageVO);
    }

    @ApiOperation("NB表历史数据分页列表")
    @SystemLogRecordMonitor("NB表历史数据分页列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "customerSerialnumber", value = "客户编号", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "customerName", value = "客户名称", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "archivesAddress", value = "表计地址", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "imei", value = "Imei", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "beginDate", value = "开始时间", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "endDate", value = "结束时间", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "areaId", value = "区域id", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "pageNum", value = "页码", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "orderColumn", value = "排序字段", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "orderType", value = "排序类型(asc,desc)", dataType = "string", paramType = "query", example = "", required = false),
    })
    @PostMapping("/getNBMeterHistoryPageVO")
    public ResponseEntity<PageVO<MeterHistoryPageVO>> getNBMeterHistoryPageVO(
            @RequestParam(value = "customerSerialnumber",required = false)String customerSerialnumber,
            @RequestParam(value = "areaName",required = false)String areaName,
            @RequestParam(value = "archivesAddress",required = false)String archivesAddress,
            @RequestParam(value = "imei",required = false)String imei,
            @RequestParam(value = "beginDate",required = false)String beginDate,
            @RequestParam(value = "endDate",required = false)String endDate,
            @RequestParam(value = "areaId",required = false)Integer areaId,
            @RequestParam(value = "pageSize",required = false,defaultValue = "10")Integer pageSize,
            @RequestParam(value = "pageNum",required = false,defaultValue = "1")Integer pageNum,
            @RequestParam(value = "orderColumn",required = false,defaultValue = "a.read_time") String orderColumn,
            @RequestParam(value = "orderType",required = false,defaultValue = "desc") String orderType
    ) {

        PageVO<MeterHistoryPageVO> pageVO = reportNbWaterDataService.getNBMeterHistoryPageVO(customerSerialnumber,areaName,
                archivesAddress,imei,beginDate,endDate,areaId,pageSize,pageNum,orderColumn,orderType);
        return new ResponseEntity<>(pageVO);
    }

    @ApiOperation("NB表历史数据图表")
    @SystemLogRecordMonitor("NB表历史数据图表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "archivesAddress", value = "表计地址", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "imei", value = "Imei", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "beginDate", value = "开始时间", dataType = "string", paramType = "query", example = "", required = true),
            @ApiImplicitParam(name = "endDate", value = "结束时间", dataType = "string", paramType = "query", example = "", required = true),
            @ApiImplicitParam(name = "areaId", value = "区域id", dataType = "string", paramType = "query", example = "", required = false),
    })
    @PostMapping("/getNBMeterHistoryChartVO")
    public ResponseEntity<List<ChartVO>> getNBMeterHistoryChartVO(
            @RequestParam(value = "archivesAddress",required = false)String archivesAddress,
            @RequestParam(value = "imei",required = false)String imei,
            @RequestParam(value = "beginDate",required = true)String beginDate,
            @RequestParam(value = "endDate",required = true)String endDate,
            @RequestParam(value = "areaId",required = false)Integer areaId
    ) {

        List<ChartVO> chartVOList = reportNbWaterDataService.getNBMeterHistoryChartVO(archivesAddress,imei,
                beginDate,endDate,areaId);
        return new ResponseEntity<>(chartVOList);
    }

    @ApiOperation("NB表实时数据分页列表")
    @SystemLogRecordMonitor("NB表实时数据分页列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "customerSerialnumber", value = "客户编号", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "customerName", value = "客户名称", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "archivesAddress", value = "表计地址", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "imei", value = "Imei", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "areaId", value = "区域id", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "pageNum", value = "页码", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "orderColumn", value = "排序字段", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "orderType", value = "排序类型(asc,desc)", dataType = "string", paramType = "query", example = "", required = false),
    })
    @PostMapping("/getNBMeterRealTimePageVO")
    public ResponseEntity<PageVO<MeterRealtimePageVO>> getNBMeterRealTimePageVO(
            @RequestParam(value = "customerSerialnumber",required = false)String customerSerialnumber,
            @RequestParam(value = "areaName",required = false)String areaName,
            @RequestParam(value = "archivesAddress",required = false)String archivesAddress,
            @RequestParam(value = "imei",required = false)String imei,
            @RequestParam(value = "areaId",required = false)Integer areaId,
            @RequestParam(value = "pageSize",required = false,defaultValue = "10")Integer pageSize,
            @RequestParam(value = "pageNum",required = false,defaultValue = "1")Integer pageNum,
            @RequestParam(value = "orderColumn",required = false,defaultValue = "c.archivesAddress") String orderColumn,
            @RequestParam(value = "orderType",required = false,defaultValue = "asc") String orderType
    ) {

        PageVO<MeterRealtimePageVO> pageVO = reportNbWaterDataService.getNBMeterRealTimePageVO(customerSerialnumber, areaName,
                archivesAddress, imei, areaId, pageSize, pageNum, orderColumn, orderType);
        return new ResponseEntity<>(pageVO);
    }

    @ApiOperation("NB表冻结数据分页列表")
    @SystemLogRecordMonitor("NB表冻结数据分页列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "customerSerialnumber", value = "客户编号", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "customerName", value = "客户名称", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "archivesAddress", value = "表计地址", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "imei", value = "Imei", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "beginDate", value = "开始时间", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "endDate", value = "结束时间", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "areaId", value = "区域id", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "pageNum", value = "页码", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "orderColumn", value = "排序字段", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "orderType", value = "排序类型(asc,desc)", dataType = "string", paramType = "query", example = "", required = false),
    })
    @PostMapping("/getNBMeterFrozenPageVO")
    public ResponseEntity<PageVO<MeterFrozenPageVO>> getNBMeterFrozenPageVO(
            @RequestParam(value = "customerSerialnumber",required = false)String customerSerialnumber,
            @RequestParam(value = "areaName",required = false)String areaName,
            @RequestParam(value = "archivesAddress",required = false)String archivesAddress,
            @RequestParam(value = "imei",required = false)String imei,
            @RequestParam(value = "beginDate",required = false)String beginDate,
            @RequestParam(value = "endDate",required = false)String endDate,
            @RequestParam(value = "areaId",required = false)Integer areaId,
            @RequestParam(value = "pageSize",required = false,defaultValue = "10")Integer pageSize,
            @RequestParam(value = "pageNum",required = false,defaultValue = "1")Integer pageNum,
            @RequestParam(value = "orderColumn",required = false,defaultValue = "c.archivesAddress") String orderColumn,
            @RequestParam(value = "orderType",required = false,defaultValue = "asc") String orderType
    ) {

        PageVO<MeterFrozenPageVO> pageVO = reportNbWaterDataService.getNBMeterFrozenPageVO(customerSerialnumber,areaName,
                archivesAddress,imei,beginDate,endDate,areaId,pageSize,pageNum,orderColumn,orderType);
        return new ResponseEntity<>(pageVO);
    }

    @ApiOperation("NB表冻结数据图表")
    @SystemLogRecordMonitor("NB表冻结数据图表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "archivesAddress", value = "表计地址", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "imei", value = "Imei", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "beginDate", value = "开始时间", dataType = "string", paramType = "query", example = "", required = true),
            @ApiImplicitParam(name = "endDate", value = "结束时间", dataType = "string", paramType = "query", example = "", required = true),
            @ApiImplicitParam(name = "areaId", value = "区域id", dataType = "string", paramType = "query", example = "", required = false),
    })
    @PostMapping("/getNBMeterFrozenChartVO")
    public ResponseEntity<List<ChartVO>> getNBMeterFrozenChartVO(
            @RequestParam(value = "archivesAddress",required = false)String archivesAddress,
            @RequestParam(value = "imei",required = false)String imei,
            @RequestParam(value = "beginDate",required = true)String beginDate,
            @RequestParam(value = "endDate",required = true)String endDate,
            @RequestParam(value = "areaId",required = false)Integer areaId
    ) {

        List<ChartVO> chartVOList = reportNbWaterDataService.getNBMeterFrozenChartVO(archivesAddress,imei,
                beginDate,endDate,areaId);
        return new ResponseEntity<>(chartVOList);
    }
}
